package com.opencloud.iot.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opencloud.common.model.PageParams;
import com.opencloud.iot.client.model.entity.IotConfigs;
import com.opencloud.iot.client.model.entity.IotTask;
import com.opencloud.iot.provider.mapper.IotConfigsMapper;
import com.opencloud.iot.provider.mapper.IotTaskMapper;
import com.opencloud.iot.provider.service.IotConfigsService;
import com.opencloud.iot.provider.service.IotTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 进出记录操作
 * @author yeyong
 */

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class IotTaskServiceImpl implements IotTaskService {

    @Autowired
    private IotTaskMapper iotTaskMapper;

    @Override
    public IPage<IotTask> findListPage(PageParams pageParams) {
        QueryWrapper<IotTask> queryWrapper = new QueryWrapper();
        queryWrapper.lambda();
        return iotTaskMapper.selectPage(new Page(pageParams.getPage(),pageParams.getLimit()),queryWrapper);
    }

    @Override
    public List<IotTask> findTaskByType(Integer tasktype) {
        QueryWrapper<IotTask> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(ObjectUtils.isNotEmpty(tasktype),IotTask::getTasktype,tasktype)
                .orderByDesc(IotTask::getCreatetime);
        return iotTaskMapper.selectList(queryWrapper);
    }

    @Override
    public Integer AddTask(IotTask entiy)
    {
        return iotTaskMapper.insert(entiy);
    }

    @Override
    public Integer UpdateTask(IotTask entiy)
    {
        return iotTaskMapper.updateById(entiy);
    }

}
